#include "tools.h"
#include <QProcess>


QString tools::extractXmlTagBody(QString xmlText, QString tagName)
{
	QString body;
	QString openTag = QString("<%1>").arg(tagName);
	QString closeTag = QString("</%1>").arg(tagName);

	int bodyBeginIndex = xmlText.indexOf(openTag);
	if (bodyBeginIndex >= 0)
	{
		bodyBeginIndex += openTag.length();

		if ( bodyBeginIndex > 0 && bodyBeginIndex < xmlText.length() )
		{
			int bodyEndIndex = xmlText.indexOf(closeTag, bodyBeginIndex + 1);
			if (bodyEndIndex > 0)
			{
				int bodyLen = bodyEndIndex - bodyBeginIndex;

				if (bodyLen > 0)
					body = xmlText.mid(bodyBeginIndex, bodyLen);
			}
		}
	}

	return body;
}

bool tools::runApplication(const QString &applicationFilePath)
{
	return QProcess::startDetached(applicationFilePath);
}
